# -*- coding: utf-8 -*-
"""
    Author:
    Date: 2019-11-26

    微信开发的辅助类配置文件.
"""

import env

# ------------------------------------------------
# 微信公众号用户标签
# ------------------------------------------------

WXTAG_ADMIN             = 100  # 管理员: admin

# ------------------------------------------------
# 微信公众号
# ------------------------------------------------

APPID = env.WX_APP_ID   # 微信appid
APPSECRET = env.WX_APP_SECRET  # 微信AppSecret
SERVER_IP = env.WX_SERVER_IP  # 服务器的IP地址


# ------------------------------------------------
# 微信商户平台
# ------------------------------------------------

# 支持微信公众号支付的商户号
WX_MCH_IDS_FOR_MP = env.WX_MCH_IDS_FOR_MP
# 支持微信H5页面支付的商户号
WX_MCH_IDS_FOR_H5 = env.WX_MCH_IDS_FOR_H5

MCH_ID = env.WX_MCH_ID  # 微信商户id
API_KEY = env.WX_API_KEY  # 微信支付密钥
MCH_NAME = env.WX_MCH_NAME  # 商户名称

MCH_CERT_PATH = env.WX_MCH_CERT_PATH  #
MCH_CERT_KEY_PATH = env.WX_MCH_CERT_KEY_PATH  #

WX_AGENT_RED_PACK_CLIENT_IP = env.WX_AGENT_RED_PACK_CLIENT_IP

# 微信内置浏览器用户授权获取code后的回调页面
WXWEB_REDIRECT_URI = env.WXWEB_REDIRECT_URI
# 充值回调通知地址
WXWEB_PAY_NOTIFY_URL = env.WXWEB_PAY_NOTIFY_URL

# ------------------------------------------------
# 微信网页开发配置参数
# 参见: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
# ------------------------------------------------

# 微信内置浏览器用户授权获取code的请求参数scope
WXWEB_SCOPE = 'snsapi_userinfo'
# 微信内置浏览器用户授权获取code的请求参数state, 重定向后会返回state参数
WXWEB_STATE = '8w&R!6'

# 微信内置浏览器获取code微信接口
DEFAULT_WXWEB_GET_CODE_URL = 'https://open.weixin.qq.com/connect/oauth2/authorize'
# 微信内置浏览器获取access_token微信接口
DEFAULT_WXWEB_GET_ACCESS_TOKEN_URL = 'https://api.weixin.qq.com/sns/oauth2/access_token'
# 微信内置浏览器获取用户信息微信接口
DEFAULT_WXWEB_GET_USER_INFO_URL = 'https://api.weixin.qq.com/sns/userinfo'
# 微信下单的接口
DEFAULT_UNIFIED_ORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder"

# ------------------------------------------------
# 微信API配置参数
# ------------------------------------------------

WXAPI_ACCESS_TOKEN_KEY = 'wechat_api_access_token'
WXAPI_ACCESS_TOKEN_EXPIRES_KEY = 'wechat_api_access_token_expires_in'

# 微信公众平台API获取access_token的接口请求地址
DEFAULT_WXAPI_GET_ACCESS_TOKEN_URL = 'https://api.weixin.qq.com/cgi-bin/token'

# 微信公众平台API获取用户标签列表的请求地址
DEFAULT_WXAPI_GET_TAGS_URL = 'https://api.weixin.qq.com/cgi-bin/tags/get'
# 微信公众平台API设置自定义菜单的请求地址
DEFAULT_WXAPI_SET_MENU = 'https://api.weixin.qq.com/cgi-bin/menu/create'
# 微信公众平台API设置个性化菜单的请求地址
DEFAULT_WXAPI_SET_CUSTOM_MENU = 'https://api.weixin.qq.com/cgi-bin/menu/addconditional'

# 微信公众平台创建二维码的请求地址
DEFAULT_WXAPI_CREATE_QR_TICKET = 'https://api.weixin.qq.com/cgi-bin/qrcode/create'
# 微信公众平台换取二维码的请求地址
DEFAULT_WXAPI_SHOW_QR_CODE = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'

# 微信公众平台获取用户基本信息的请求地址
DEFAULT_WXAPI_GET_USER_INFO = 'https://api.weixin.qq.com/cgi-bin/user/info'
# 微信公众平台:给用户打标签
DEFAULT_WXAPI_TAG_USER_URL = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging'
# 微信公众平台:取消用户标签
DEFAULT_WXAPI_UNTAG_USER_URL = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging'

WXAPI_JSAPI_TICKET_KEY = 'wechat_api_jsapi_ticket'
WXAPI_JSAPI_TICKET_EXPIRES_KEY = 'wechat_api_jsapi_ticket_expires_in'

# 微信公众平台:获取JS接口票据
DEFAULT_WXAPI_GET_JSAPI_TICKET_URL = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket'

# 微信公众平台: 发红包请求地址
DEFAULT_WXAPI_SEND_RED_PACK_URL = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'
# 微信公众平台: 红包订单查询地址
DEFAULT_WXAPI_RED_PACK_ORDER_QUERY_URL = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/gethbinfo'
# DEFAULT_WXAPI_RED_PACK_ORDER_QUERY_URL = 'https://api.mch.weixin.qq.com/pay/orderquery'


# ------------------------------------------------
# 微信公众号个性化菜单
# ------------------------------------------------

def wx_callback(redirect_uri):
    url = f"{DEFAULT_WXWEB_GET_CODE_URL}?appid={APPID}&redirect_uri={redirect_uri}&response_type=code&scope=snsapi_base&state={WXWEB_STATE}#wechat_redirect"
    return url

# 微信公众平台: 充值地址(官方)
WX_MP_HAIBAO_BUY_DIAMOND_URL = wx_callback("https://m.yyzb.com/mp/pay/")
# 微信公众平台: 充值地址(银联)
WX_MP_HAIBAO_BUY_DIAMOND_UNIPAY_URL = "https://res.yyzb.com/tool/unipaymp/index.html"
# 微信公众平台: 提现地址
WX_MP_HAIBAO_WITHDRAW_URL = wx_callback("https://m.yyzb.com/mp/withdraw/")
# 微信公众平台: 下载地址
WX_MP_HAIBAO_DOWNLOAD_URL = wx_callback("https://m.yyzb.com/mp/download/haibao/")
# 微信公众平台: 关于我们页面
WX_MP_HAIBAO_ABOUT_US_URL = wx_callback("https://m.yyzb.com/mp/about/")

# 默认的个性化菜单设置
CUSTOM_MENU_FOR_EVERYONE = {
    "button": [
        {
            "name": "获取钻石",
            "sub_button": [
                {
                    "type": "view",
                    "name": "获取钻石",
                    # "url": WX_MP_HAIBAO_BUY_DIAMOND_URL,
                    "url": WX_MP_HAIBAO_BUY_DIAMOND_UNIPAY_URL,
                },
                # {
                #     "type": "view",
                #     "name": "提 现",
                #     "url": WX_MP_HAIBAO_WITHDRAW_URL,
                # },
            ]
        },
        # {
        #     "type": "view",
        #     "name": "充值",
        #     "url": WX_MP_HAIBAO_BUY_DIAMOND_URL,
        # },
        {
            "type": "view",
            "name": "APP下载",
            "url": WX_MP_HAIBAO_DOWNLOAD_URL,
        },
        # {
        #     "type": "view",
        #     "name": "关于我们",
        #     "url": WX_MP_HAIBAO_ABOUT_US_URL
        # },
    ]
}

# 管理员个性化菜单设置
CUSTOM_MENU_FOR_ADMIN = {
    "button": [
        {
            "name": "充值",
            "sub_button": [
                {
                    "type": "view",
                    "name": "充值",
                    "url": WX_MP_HAIBAO_BUY_DIAMOND_URL,
                },
                # {
                #     "type": "view",
                #     "name": "提现",
                #     "url": WX_MP_HAIBAO_WITHDRAW_URL,
                # },
                {
                    "type": "view",
                    "name": "UNIPAY TEST",
                    "url": 'https://res.yyzb.com/tool/unipaymp/index.html#/?env=testing',
                },
                {
                    "type": "view",
                    "name": "UNIPAY PROD",
                    "url": WX_MP_HAIBAO_BUY_DIAMOND_UNIPAY_URL,
                },
            ]
        },
        {
            "type": "view",
            "name": "APP下载",
            "url": WX_MP_HAIBAO_DOWNLOAD_URL,
        },
    ],
    "matchrule": {
        "tag_id": f"{WXTAG_ADMIN}",
    }
}

APP_DOWNLOAD_PAGE_IN_WX_URL = 'https://www.yyzb.com/download.html?channel=wx'


if __name__ == '__main__':
    print('ok')
